package com.ciko.code.adapter;

import android.content.Context;
import android.view.View;

import com.ciko.code.base.adapter.CommonAdapter;
import com.ciko.code.base.adapter.ViewHolder;
import com.ciko.code.http.Req.GetOverTimeFlowsBySelfEty;
import com.ciko.code.utils.DateUtil;
import com.ciko.code.utils.Util;
import com.mywork.R;
import com.mywork.WorkUIKit;

import java.util.List;

/**
 * Created by ciko on 2015/12/9.
 */
public class ResListOverWorkAdapter extends CommonAdapter<GetOverTimeFlowsBySelfEty> {
    private int TYPE = 0;//1,审批，0，发起
    String content;

    public ResListOverWorkAdapter(int TYPE,Context context, List<GetOverTimeFlowsBySelfEty> mDatas, int itemLayoutId) {
        super(context, mDatas, itemLayoutId);
        this.TYPE = TYPE;

    }

    @Override
    public void convert(ViewHolder helper, GetOverTimeFlowsBySelfEty item) {
        helper.setText(R.id.tv_timeLeave, DateUtil.longToDate(item.getWorkFlow().getCreateTime(), 0));
        helper.setText(R.id.tv_typeLeave, item.getOverTimeType());
//        helper.setText(R.id.tv_dayCountLeave, df.format((item.getOverTimeDays()* (24 * 3600) / 3600.0)) + "小时");
        helper.setText(R.id.tv_dayCountLeave, Util.getDayAndHour((int) item.getOverTimeDays()));
        helper.setText(R.id.tv_sendPersonLeave, item.getUserName());
        helper.getView(R.id.tv_sendPersonLeave).setVisibility(TYPE == 1 ? View.VISIBLE : View.GONE);
        helper.setText(R.id.tv_stateLeave, item.getWorkFlow().getNodeName());
        if (TYPE == 1){
            if (!("归档".equals(item.getWorkFlow().getNodeName()) || "失败".equals(item.getWorkFlow().getNodeName()) || item.getNextUserId() != WorkUIKit.getUser().getId()))
            {   helper.setTextColor(R.id.tv_timeLeave, R.color.red_dot);
                helper.setTextColor(R.id.tv_typeLeave, R.color.red_dot);
                helper.setTextColor(R.id.tv_dayCountLeave, R.color.red_dot);
                helper.setTextColor(R.id.tv_stateLeave, R.color.red_dot);
                helper.setTextColor(R.id.tv_sendPersonLeave,R.color.red_dot);
            }
            else {
                helper.setTextColor(R.id.tv_timeLeave, R.color.text_black_4);
                helper.setTextColor(R.id.tv_typeLeave, R.color.text_black_4);
                helper.setTextColor(R.id.tv_dayCountLeave, R.color.text_black_4);
                helper.setTextColor(R.id.tv_stateLeave, R.color.text_black_4);
                helper.setTextColor(R.id.tv_sendPersonLeave,R.color.text_black_4);
            }
        }
        // TODO 根据state来确定不同的状态
//        switch (item.getWorkFlow().getStatus()) {
//            case 0:
//                helper.setText(R.id.tv_stateLeave, "未审批");
//                break;
//            case 1:
//                helper.setText(R.id.tv_stateLeave, "未审批");
//                break;
//            case 3:
//                helper.setText(R.id.tv_stateLeave, "未审批");
//                break;
//        }
        helper.getView(R.id.tv_stateLeave).setVisibility(TYPE == 1 ? View.GONE : View.VISIBLE);
    }

}
